import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class DanceMidlet extends MIDlet implements CommandListener {

	private Display display;
	private Command comExit;

	public DanceMidlet() {
		display = Display.getDisplay(this);
		comExit = new Command("Sair", Command.EXIT, 0);
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		notifyDestroyed();
	}

	protected void pauseApp() {
	}

	protected void startApp() throws MIDletStateChangeException {
		Canvas canvas = new ExemploCanvas1();
		canvas.addCommand(comExit);
		canvas.setCommandListener(this);
		display.setCurrent(canvas);
	}

	public void commandAction(Command c, Displayable d) {
		if (c.equals(comExit)) {
			try {
				destroyApp(true);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
		}
	}

	class ExemploCanvas1 extends Canvas {

		protected void paint(Graphics g) {
			int largura = getWidth();
			int altura = getHeight();
			g.setColor(0, 255, 0);
			g.fillRect(10, 10, largura - 100, altura - 20);
			g.setColor(255, 255, 255);
			g.fillArc(50, 50, largura - 100, altura - 100, 0, 360);
			g.setColor(0, 0, 0);
			g.fillArc(87, 100, 20, 20, 0, 360);
			g.fillArc(137, 100, 20, 20, 0, 360);
			g.setColor(255, 51, 51);
			g.fillArc(95, 150, 50, 50, 205, 130);
			g.setColor(100, 0, 255);
			g.drawString("Hello World", largura / 2, altura - 40, Graphics.TOP
					| Graphics.HCENTER);
		}

	}

}
